package com.zetyun.tiger.json;

import cn.hutool.core.io.FileUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.json.JSONUtil;
import com.zetyun.tiger.sql.dkm.GenSrDkmApp;

import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.*;

public class JobConfigApp {

    public static void main(String[] args) throws  SQLException {

        ArrayList<Map<String,String>> list = new ArrayList<>();


        String jobConFTemplate = FileUtil.readString(Objects.requireNonNull(
                GenSrDkmApp.class.getResource("/jobconfig.sql")), StandardCharsets.UTF_8);

        //查询
        List<Entity> result = Db.use()
                .query(jobConFTemplate);



        for (Entity entity : result) {
            String topic_name = entity.getStr("topic_name");
            String tb_cn_name = entity.getStr("tb_cn_name");
            String column_name = entity.getStr("column_name");
            HashMap<String, String> map = new HashMap<>();

            map.put("fullTbName",topic_name);
            map.put("tbCnName",tb_cn_name);
            map.put("dateField",column_name);


            list.add(map);
        }
        String str = JSONUtil.toJsonStr(list);
        FileUtil.writeString(str,"job-conf.json",StandardCharsets.UTF_8);
    }


}

